package serviceset1.restTemplate

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand
import grails.gorm.transactions.Transactional
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.client.RestTemplate

@Transactional
class ServiceSet2ProxyService {

    @Autowired
    RestTemplate restTemplate

    @HystrixCommand(commandKey = "ServiceSet2ProxyService#sampleApi2(String)", fallbackMethod = "reliable")
    Map sampleApi2(String dependency) {
        def service_uri = "http://SERVICE-SET-2/sampleApi2?dependency={dependency}", args = [dependency: dependency]

        restTemplate.getForObject(service_uri, Map.class, args)
    }

    Map reliable(String dependency) {
        [provider: "sampleApi2@serviceSet2", dependency: dependency, state: "offline"]
    }
}
